package io.bdmc.modules.bss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.bdmc.common.utils.MyPage;
import io.bdmc.modules.bss.entity.DeviceFibreMatch;
import io.bdmc.modules.bss.mapper.DeviceFibreMatchMapper;
import io.bdmc.modules.bss.service.IDeviceFibreMatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 设备通道与光纤芯序号对照表 服务实现类
 * </p>
 *
 * @author 黄露
 * @since 2020-08-14
 */
@Service
public class DeviceFibreMatchServiceImpl extends ServiceImpl<DeviceFibreMatchMapper, DeviceFibreMatch> implements IDeviceFibreMatchService {
    @Autowired
    DeviceFibreMatchMapper matchMapper;

    @Override
    public MyPage<DeviceFibreMatch> mySelectPage(MyPage<DeviceFibreMatch> myPage) {
        return matchMapper.mySelectPage(myPage);
    }

    @Override
    public List<DeviceFibreMatch> selectByDeviceSn(String deviceSn) {
        return matchMapper.selectByDeviceSn(deviceSn);
    }

    @Override
    public List<DeviceFibreMatch> ListMeasureDevice() {
        return matchMapper.ListMeasureDevice();
    }

    @Override
    public DeviceFibreMatch selectByDeviceSnAndChannel(String deviceSn,Integer channel) {
        QueryWrapper<DeviceFibreMatch> w1 = new QueryWrapper<>();
        w1.eq("device_sn",deviceSn).eq("channel",channel).last("limit 1");
        return getOne(w1);
    }

    @Override
    public DeviceFibreMatch selectByDeviceIdAndChannel(Integer deviceId, Integer channel) {
        QueryWrapper<DeviceFibreMatch> w1 = new QueryWrapper<>();
        w1.eq("device_id",deviceId).eq("channel",channel).last("limit 1");
        return getOne(w1);
    }

    /**
     * 解除指定设备的所有绑定关系
     *
     * @param deviceSn 设备sn
     * @return 解除结果
     */
    @Override
    public Boolean unbindDeviceBySn(String deviceSn) {
        return remove(new QueryWrapper<DeviceFibreMatch>().eq("device_sn", deviceSn));
    }

    @Override
    public List<DeviceFibreMatch> selectBindFibreMatch(int deptId){
        return matchMapper.selectBindFibreMatch(deptId);
    }
}
